<template>

	<view class="flowLaunch-v">

		<!-- 搜索 -->
		<view class="search-box search-box_sticky">
			<u-search placeholder="请输入编号搜索" v-model="keyword" height="72" :show-action="false" @change="search"
				bg-color="#f0f2f6" shape="square">
			</u-search>
		</view>

		<!-- 列表 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :sticky="true"
			:down="downOption" :up="upOption">

			<view class="flow-list" v-if="list.length > 0">
				<view class="flow-list-box">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item v-for="(item, index) in list" :key="item.id" :threshold="0"
							:right-options="options" @click="handleClick(index)" class="data-item">
							<view class="item" @click="goDetail(item)" :id="'item'+index" ref="mydom"
								style="height: 240px;">
								<view class="item-left">

									<text class="title u-line-1 u-font-24">编号 :<text
											class="titInner">{{item.code ? item.code : ''}}</text></text>
									<text class="title u-line-1 u-font-24">QMS检验批 :<text
											class="titInner">{{item.inspectionLot ? item.inspectionLot : ''}}</text>
									</text>
									<text class="title u-line-1 u-font-24">批次 :<text
											class="titInner">{{item.batchNumber ? item.batchNumber : ''}}</text>
									</text>
									<text class="title u-line-1 u-font-24">物料编码 :<text
											class="titInner">{{item.materialCode ? item.materialCode : ''}}</text></text>
									<text class="title u-line-1 u-font-24">来料数量 :<text
											class="titInner">{{item.incomingQty ? item.incomingQty : ''}}</text></text>
									<text class="title u-line-1 u-font-24">问题原因 :<text
											class="titInner">{{item.problem ? item.problem : ''}}</text></text>
									<text class="title u-line-1 u-font-24">使用决策 :<text
											class="titInner">{{item.decisionName ? item.decisionName : ''}}</text></text><text
										class="title u-line-1 u-font-24">创建人 :<text
											class="titInner">{{item.creatorUser ? item.creatorUser : ''}}</text></text>
									<text class="time title u-font-24">创建日期 :<text
											class="titInner">{{item.createTime | date('yyyy-mm-dd')}}</text></text>
								</view>
								<view class="item-right">
									<image :src="item.flowStatus" mode="widthFix" class="item-right-img">
									</image>
								</view>
							</view>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>
<script>
	import resources from '@/libs/resources.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		defecthandle

	} from '@/api/q1/business/inspection/unqualifiedreview.js'
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				flowStatus: '',
				downOption: {
					use: true,
					auto: true
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					empty: {
						use: true,
						icon: resources.message.nodata,
						tip: "暂无数据",
						fixed: true,
						top: "300rpx",
					},
					textNoMore: '没有更多数据',
				},
				keyword: '',
				list: [],
				options: [{
					text: '查看详情',
					style: {
						backgroundColor: '#c1c1c1'
					}
				}]
			}
		},
		onShow(e) {

			uni.$on('refresh', () => {
				this.list = [];
				this.mescroll.resetUpScroll();
			})

		},
		onUnload() {
			uni.$off('refresh')
		},

		methods: {
			//获取上个页面数据
			getValue(result) {

				if (result == 'success') {

					this.upCallback({
						num: 1,
						size: 10
					})
				}
			},

			upCallback(page) {
				let query = {
					currentPage: page.num,
					pageSize: page.size,
					code: this.keyword
				}
				defecthandle(query, {
					load: page.num == 1
				}).then(res => {

					this.mescroll.endSuccess(res.data.list.length);
					if (page.num == 1) this.list = [];
					const list = res.data.list.map(o => ({
						'flowStatus': this.getFlowStatus(o.status),
						...o
					}))
					this.list = this.list.concat(list);
				}).catch(() => {
					this.mescroll.endErr();
				})
			},

			getFlowStatus(status) {
				let flowStatus;
				switch (status) {
					case 0: //等待提交
						flowStatus = resources.status.submitwait
						break;
					case 1: //等待审核
						flowStatus = resources.status.checkwait
						break;
					case 2: //审核通过
						flowStatus = resources.status.checkpass
						break;
					case 3: //流程驳回
						flowStatus = resources.status.checkreject
						break;
					case 4: //流程撤回
						flowStatus = resources.status.checkrecall
						break;
					case 5: //审核终止
						flowStatus = resources.status.checktermination
						break;
					case 6: //完成
						flowStatus = resources.status.checkfinish
						break;
				}
				return flowStatus
			},
			handleClick(index) {
				const item = this.list[index]
				
				if (item.status == 0) {
					return this.$u.toast("当前任务不能查看!")
				} else {

					uni.navigateTo({

						url: '/pages/q1/business/unqualifiedreview/reviewdetail?id='+ item.id 
							+ '&status='+ item.status 
							+ '&instype=' + item.type
					})
				}

			},

			search() {
				// 节流,避免输入过快多次请求
				this.searchTimer && clearTimeout(this.searchTimer)
				this.searchTimer = setTimeout(() => {
					this.list = [];
					this.mescroll.resetUpScroll();
				}, 300)
			},
			goDetail(item) {
				if (item.status == 3 || item.status == 0) {
					uni.navigateTo({
						url: '/pages/q1/business/unqualifiedreview/reviewedit?id='
							+ item.id
							+ '&status=' + item.status
							+ "&type=edit" + '&instype=' + item.type
					})
				} else {
					uni.navigateTo({
					
						url: '/pages/q1/business/unqualifiedreview/reviewdetail?id='
							+ item.id 
							+ '&status='+ item.status + '&instype=' + item.type
					})
				}

			}

		},



	}
</script>

<style lang="scss" scoped>
	// page {
	// 	background-color: #f0f2f6;
	// }

	@import "@/assets/scss/common.scss";

	page {
		background-color: #f0f2f6;
		height: 100%;
		/* #ifdef MP-ALIPAY */
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		/* #endif */
	}

	.flow-list{
		padding-top: 5px;
		padding-bottom: 5px;
	}
	
	.flow-list .data-item {
		margin-bottom: 10px;
	}

	.w-100 {
		width: 100rpx;
	}

	.flowLaunch-v {
		width: 100%;

		.flow-list-box {
			width: 95%;

			.item-left-top {
				display: flex;
				width: 100%;

				.common-lable {
					font-size: 24rpx;
					padding: 2rpx 8rpx;
					margin-right: 8rpx;
					border-radius: 8rpx;
					color: #ffffff;
					border: 1px solid #ffffff;
					background-color: #6dcc51;
				}

				.urgent-lable {
					color: #E6A23C;
					border: 1px solid #E6A23C;
					background-color: #fef6e5;
				}

				.important-lable {
					color: #F56C6C;
					border: 1px solid #F56C6C;
					background-color: #fee5e5;
				}

				.title {
					width: unset;
					flex: 1;
					min-width: 0;
				}
			}
		}
	}
</style>